package com.meiyu.live.ui.main.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.meiyu.live.R;
import com.meiyu.live.popj.LiveRoom;
import com.meiyu.live.tv.audience.AudienceActivity;

public class ColumnDetailItemView extends FrameLayout implements View.OnClickListener {

    private TextView tv_name;
    private ImageView iv_tv;

    private ImageLoader imageLoader;
    private DisplayImageOptions options;

    private LiveRoom bean;

    public ColumnDetailItemView(Context context) {
        super(context);
        init(context);
    }

    public ColumnDetailItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public ColumnDetailItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        LayoutInflater inflater = LayoutInflater.from(context);
        inflater.inflate(R.layout.adapter_column_itemdetail, this);
        tv_name = (TextView) findViewById(R.id.tv_name);
        iv_tv = (ImageView) findViewById(R.id.iv_tv);
        setOnClickListener(this);
    }

    public void setImageLoader(ImageLoader imageLoader, DisplayImageOptions options) {
        this.imageLoader = imageLoader;
        this.options = options;
    }

    public void setData(LiveRoom bean) {
        this.bean = bean;
        tv_name.setText(bean.getDescription());
        imageLoader.displayImage(bean.getImage_url(), iv_tv, options);
    }

    @Override
    public void onClick(View view) {
        if (bean != null){
            AudienceActivity.start(getContext(), bean);
        }
    }
}
